package com.hdyg.sixg.activity.home;

import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.allen.library.SuperTextView;
import com.hdyg.sixg.R;
import com.hdyg.sixg.activity.common.BaseActivity;
import com.hdyg.sixg.mvp.Contrant.CForwardInverst;
import com.hdyg.sixg.mvp.base.BaseUrl;
import com.hdyg.sixg.mvp.base.GetParamUtil;
import com.hdyg.sixg.mvp.base.SpMsg;
import com.hdyg.sixg.mvp.presenter.PForwardInverst;
import com.hdyg.sixg.util.StringUtil;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import butterknife.BindView;

/**
 * @author CZB
 * @describe 投资钱包转出
 * @time 2019/4/9 10:58
 */
public class InversTransActivity extends BaseActivity implements CForwardInverst.IVForwardInverst {
    @BindView(R.id.ll_top_left)
    LinearLayout llTopLeft;
    @BindView(R.id.tvTopTitle)
    TextView tvTopTitle;
    @BindView(R.id.sv_money)
    SuperTextView svMoney;
    @BindView(R.id.et_number)
    EditText etNumber;
    @BindView(R.id.et_pay_pwd)
    EditText etPayPwd;
    @BindView(R.id.bt_sure)
    Button btSure;
    @BindView(R.id.srl_refresh)
    SmartRefreshLayout srlRefresh;

    private CForwardInverst.IPForwardInverst mPresenter;
    private String amount,trapass;
    private String investMoney;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_invers_trans;
    }

    @Override
    protected void initView() {
        onClickListener();
        tvTopTitle.setText(R.string.invers_trans);
        investMoney = getIntent().getStringExtra(SpMsg.INTENT_STR);
        svMoney.setRightString(investMoney);
    }
    private void onClickListener(){
        srlRefresh.setOnRefreshListener(refreshLayout -> {
            srlRefresh.finishRefresh(2000);//传入false表示刷新失败
        });
        llTopLeft.setOnClickListener(v -> finish());
        btSure.setOnClickListener(v -> {
            amount = etNumber.getText().toString().trim();
            trapass = etPayPwd.getText().toString().trim();
            if (TextUtils.isEmpty(amount)){
                toastNotifyShort(R.string.trans_number_hint);
                return;
            }
            if (TextUtils.isEmpty(trapass)){
                toastNotifyShort(R.string.pay_pwd_hint);
                return;
            }
            if (StringUtil.isFastDoubleClick()){
                return;
            }
            mPresenter.pGetForwardInvest(BaseUrl.FORWARD_INVEST_URL,GetParamUtil.getForwardInvestParam(amount,trapass));
        });
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void createPresenter() {
        mPresenter = new PForwardInverst(this);
    }

    @Override
    public void vGetForwardInvestSuccess(String dataBean) {
        toastNotifyShort(dataBean);
        setResult(RESULT_OK);
        finish();
    }
}
